package com.example.magical.normal.config;

import org.apache.pulsar.client.api.AuthenticationFactory;
import org.apache.pulsar.client.api.PulsarClient;
import org.apache.pulsar.client.api.PulsarClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ClientPulsar {
    private static final Logger LOG = LoggerFactory.getLogger(ClientPulsar.class);
    private String pulsarServiceUrl;
    private String pulsarToken;
    private PulsarClient pulsarClient;

    public ClientPulsar(String pulsarServiceUrl, String pulsarToken) {
        this.pulsarServiceUrl = pulsarServiceUrl;
        this.pulsarToken = pulsarToken;
    }

    public PulsarClient getClient() {

        try {
            pulsarClient = PulsarClient.builder()
                    .serviceUrl(pulsarServiceUrl)
                    .authentication(AuthenticationFactory.token(pulsarToken))
                    .build();
        } catch (PulsarClientException e) {
            LOG.error("PulsarClient build failure!! error={}", e.getMessage());
        }
        return pulsarClient;
    }
}
